Using :hover with :not(:disabled) in CSS
You can style buttons on hover while excluding disabled buttons by combining the :hover pseudo-class with the :not() pseudo-class. This ensures the hover effect only applies to enabled buttons.
:hover – Targets an element when the user hovers over it.
:not(:disabled) – Excludes elements that are disabled.
Combining them ensures interactive styles are applied only to elements that can be interacted with.
In this example, hovering over the 'Submit' button changes its background to dark blue, but the disabled 'Cancel' button remains gray and unresponsive to hover.
Always indicate disabled state visually to improve accessibility.
Combine :not(:disabled) with other pseudo-classes for interactive effects, like :focus or :active.
Keep hover effects subtle to maintain good UX and avoid confusion.
Test across browsers for consistent behavior, as some older browsers may render styles differently.
How would you change a button’s background color to blue when hovered, but make sure it stays gray when it’s disabled?
What happens if you write .button:hover { background: blue; } and .button:disabled { background: gray; } but the hover color still shows when disabled?
A button in our form keeps showing the hover color even when disabled — how would you debug and fix this?
We’re using a CSS framework and can’t modify the base button styles — how would you override hover behavior only for non-disabled buttons without breaking other components?
How would you design a reusable button component that handles hover and disabled states cleanly across multiple themes without specificity conflicts or CSS bloat?
In a large UI library, how do you ensure hover styles never accidentally override disabled states when developers use custom variants or dynamic class toggling?
How would you architect a theming system where hover and disabled states are decoupled and configurable at the design system level, ensuring backward compatibility during legacy component migrations?
When scaling a design system across 50+ products, how do you prevent CSS state conflicts like hover overriding disabled from becoming a recurring cross-team bug?